package com.simple.elpmobile.onlinecase.ui.component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.simple.elpmobile.domain.CaseInfo;
import com.simple.elpmobile.domain.Doctor;
import com.simple.elpmobile.onlinecase.R;
import com.simple.elpmobile.onlinecase.common.data.BaseGlobalVaribles;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CaseListAdapter extends BaseAdapter {

	private Context mContext;
	private List<CaseInfo> caseInfos;

	public CaseListAdapter(Context mContext, List<CaseInfo> caseInfos) {
		super();
		this.mContext = mContext;
		this.caseInfos = caseInfos;
	}

	@Override
	public int getCount() {
		return caseInfos.size();
	}

	@Override
	public Object getItem(int arg0) {
		return caseInfos.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View view, ViewGroup arg2) {
		view = LayoutInflater.from(mContext).inflate(R.layout.case_item, null);
		TextView info = (TextView) view.findViewById(R.id.case_info);
		TextView docTxt = (TextView) view.findViewById(R.id.doc_name);
		TextView solutionTxt = (TextView) view.findViewById(R.id.solution_txt);
		TextView creatTxt = (TextView) view.findViewById(R.id.update_time);
		info.setText(caseInfos.get(arg0).getPatientInfo());
		List<Doctor> doctors=BaseGlobalVaribles.doctors;
		if (doctors!=null) {
			for (int i = 0; i < doctors.size(); i++) {
				if (doctors.get(i).getId()==caseInfos.get(arg0).getDoctorId()) {
					docTxt.setText(doctors.get(i).getName()+"医师");
					break;
				}
			}
		}
		
		if (caseInfos.get(arg0).getSolve() == 0) {
			solutionTxt.setText("医生暂未查看你的病例！");
		} else {
			solutionTxt.setText(caseInfos.get(arg0).getSolution());
		}
		creatTxt.setText( string2Date(caseInfos.get(arg0).getCreatTime()));
		return view;
	}

	public  String string2Date(String time) {
		Date d=new Date(Long.parseLong(time));
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		time = formatter.format(d);
		return time;
	}

}
